package model

//动态生成菜单栏的
import (
	"encoding/json"
	"log"
)

type menuTreeData struct {
	menuTreeInfo
	Children []*menuTreeInfo `json:"children"`
}
type menuTreeInfo struct {
	Name string `json:"name"`
	Path string `json:"path"`
	Icon string `json:"icon"`
}

func CreateMenuTree() string {
	// 整个的数据对象
	var menuTreeList []*menuTreeData
	// App应用这一栏
	data := &menuTreeData{
		menuTreeInfo: menuTreeInfo{
			Name: "App",
			Path: "/app",
			Icon: "menu",
		},
	}
	data.Children = append(data.Children, &menuTreeInfo{
		Name: "AppUser",
		Path: "/app/user",
		Icon: "user",
	})
	data.Children = append(data.Children, &menuTreeInfo{
		Name: "AppDept",
		Path: "/app/dept",
		Icon: "office-building",
	})
	data.Children = append(data.Children, &menuTreeInfo{
		Name: "AppRole",
		Path: "/app/role",
		Icon: "avatar",
	})
	data.Children = append(data.Children, &menuTreeInfo{
		Name: "AppResource",
		Path: "/app/resource",
		Icon: "management",
	})
	menuTreeList = append(menuTreeList, data)
	// 系统这一栏
	data = &menuTreeData{
		menuTreeInfo: menuTreeInfo{
			Name: "Sys",
			Path: "/sys",
			Icon: "setting",
		},
	}
	data.Children = append(data.Children, &menuTreeInfo{
		Name: "SysUser",
		Path: "/sys/user",
		Icon: "user-filled",
	})
	data.Children = append(data.Children, &menuTreeInfo{
		Name: "SysNotice",
		Path: "/sys/notice",
		Icon: "chat-dot-round",
	})
	menuTreeList = append(menuTreeList, data)
	//logs日志部分
	data = &menuTreeData{
		menuTreeInfo: menuTreeInfo{
			Name: "Logs",
			Path: "/logs",
			Icon: "document",
		},
	}
	data.Children = append(data.Children, &menuTreeInfo{
		Name: "LogsVisit",
		Path: "/logs/visit",
		Icon: "tickets",
	})
	data.Children = append(data.Children, &menuTreeInfo{
		Name: "LogsOperation",
		Path: "/logs/operation",
		Icon: "operation",
	})
	menuTreeList = append(menuTreeList, data)
	// 输出打印
	jsonString, err := json.Marshal(menuTreeList)
	if err != nil {
		log.Fatal("Error occurred while marshaling student data", err)
	}
	//fmt.Println(string(jsonString))
	return string(jsonString)
}
